# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-climate_control
pkgver=1.2.0
pkgrel=1
pkgdesc='Modify your ENV easily with ClimateControl'
arch=(any)
url='https://github.com/thoughtbot/climate_control'
license=(MIT)
depends=(ruby)
makedepends=(ruby-rspec ruby-rake ruby-simplecov)
options=(!emptydirs)
source=(https://github.com/thoughtbot/climate_control/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('85aaf7880cb796884697bde4696e26d211ad45bab069c121205e0d12a7fa5b66')

prepare() {
  cd climate_control-$pkgver
  sed -e '/standard/d' -e 's|git ls-files|find -type f|' -i climate_control.gemspec
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd climate_control-$pkgver
  gem build climate_control.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    climate_control-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd climate_control-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rake
}

package() {
  cd climate_control-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
